package org.zxp.thread.threadlocal.contextdemo;

public class ThreadContext {
	private static ThreadLocal<TempObj> threadContext = new ThreadLocal<TempObj>() {
		public TempObj initialValue() {
			TempObj tempObj = new TempObj();
			tempObj.setValue("");
			return tempObj;
		}
	};
	
	public static void setVal(String val){
		ThreadLocal<TempObj> tmpLocal = getThreadContext();
		TempObj tmoobj = tmpLocal.get();
		tmoobj.setValue(val);
		tmpLocal.set(tmoobj);
		setThreadContext(tmpLocal);
	}
	
	public static String getVal(){
		ThreadLocal<TempObj> tmpLocal = getThreadContext();
		TempObj tmoobj = tmpLocal.get();
		return tmoobj.getValue();
	}
	
	
	public static ThreadLocal<TempObj> getThreadContext() {
		return threadContext;
	}


	public static void setThreadContext(ThreadLocal<TempObj> threadContext) {
		ThreadContext.threadContext = threadContext;
	}


	public static void removeThreadContext(ThreadLocal<TempObj> threadContext) {
		threadContext.remove();
	}
}
